package cn.iocoder.yudao.module.wrzj.controller.admin.wrzjuser.vo;

import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.wrzj.controller.app.greatman.vo.GreatmanScore;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Schema(description = "管理后台 - 伟人之家-用户 Response VO")
@Data
@ExcelIgnoreUnannotated
public class WrzjUserRespVO {

    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8923")
    @ExcelProperty("编号")
    private Long id;

    @Schema(description = "手机号")
    @ExcelProperty("手机号")
    private String mobile;

    @Schema(description = "是否被授权使用本小程序")
    private Boolean authorized;

    @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @ExcelProperty(value = "状态", converter = DictConvert.class)
    @DictFormat("common_status") // TODO 代码优化：建议设置到对应的 DictTypeConstants 枚举类中
    private Integer status;

    @Schema(description = "openid")
    @ExcelProperty("openid")
    private String openid;

    @Schema(description = "最后登录IP")
    @ExcelProperty("最后登录IP")
    private String loginIp;

    @Schema(description = "最后登录时间")
    @ExcelProperty("最后登录时间")
    private LocalDateTime loginDate;

    @Schema(description = "用户昵称", example = "芋艿")
    @ExcelProperty("用户昵称")
    private String nickname;

    @Schema(description = "用户姓名")
    @ExcelProperty("用户姓名")
    private String name;

    @Schema(description = "头像")
    @ExcelProperty("头像")
    private String avatar;

    @Schema(description = "伟人好感度")
    @ExcelProperty("伟人好感度")
    private String score;

    @Schema(description = "用户性别")
    @ExcelProperty(value = "用户性别", converter = DictConvert.class)
    @DictFormat("system_user_sex") // TODO 代码优化：建议设置到对应的 DictTypeConstants 枚举类中
    private Integer sex;

    @Schema(description = "出生日期")
    @ExcelProperty("出生日期")
    private LocalDateTime birthday;

    @Schema(description = "会员备注")
    @ExcelProperty("会员备注")
    private String mark;

    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @ExcelProperty("创建时间")
    private LocalDateTime createTime;

    @Schema(description = "已召唤伟人数量")
    private long ownedNum = 0;

    public long getOwnedNum() {
        List<GreatmanScore> greatmanScoreList = JSONObject.parseArray(score, GreatmanScore.class);
        return greatmanScoreList.stream().filter(greatmanScore -> greatmanScore.isOwned()).count();
    }
}
